<?php
 require_once 'dataprovider.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of messagersdao
 *
 * @author Circle
 */
class messagersdao {
    //put your code here
    public static function getAllMessages($id)
    {
        $sql = "SELECT UserID, DatePost, ContentOfMessage FROM messages WHERE UserID ='".$id."'";
        $result = dataprovider::ExecuteQuery($sql);
        $arrayMessage = new ArrayObject();
        while ($row = mysql_fetch_array($result)) {
            $mess = new messagerdto();
            $mess->setUserID($row['UserID']);
            $mess->setDatePost($row['DatePost']);
            $mess->setContentOfMessages($row['ContentOfMessage']);
            $arrayMessage[] = $mess;
        }
        return $arrayMessage;
    }
    
    public static function addMessage(messagerdto $message)
    {
        $sql = "INSERT INTO messages (UserID, DatePost, ContentOfMessage, Members_UserID)".
                " VALUES ('".$message->getUserID()."','".$message->getDatePost()."','".$message->getContentOfMessages()."','".$message->getUserID()."')";
        $result = dataprovider::ExecuteQuery($sql);
        if($result)
            return TRUE;
        return FALSE;
    }
}

?>
